package stock;

import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import net.sf.json.JSONArray;

import java.util.*;
import java.util.concurrent.*;

public class Test9 {

	public static float calculateAverageVolatility(List<Float> list) {
		if (list == null || list.size() < 2) {
			return 0.0f;
		}

		float sumVolatility = 0.0f;
		int count = list.size() - 1;

		for (int i = 1; i < list.size(); i++) {
			float prev = list.get(i - 1);
			float cur = list.get(i);
			sumVolatility += Math.abs((cur - prev) / prev);
		}

		return sumVolatility / count;
	}

	public static boolean isTimeDiffGreaterThanFiveMinutes(String time1, String time2) {
		int seconds1 = convertToSeconds(time1);
		int seconds2 = convertToSeconds(time2);
		int diff = Math.abs(seconds1 - seconds2);
		return diff > 300;
	}

	public static int convertToSeconds(String time) {
		int hours = Integer.parseInt(time.substring(0, 2));
		int minutes = Integer.parseInt(time.substring(2, 4));
		int seconds = Integer.parseInt(time.substring(4));
		return hours * 3600 + minutes * 60 + seconds;
	}

	// 使用 ConcurrentHashMap 存储名称和对应的数组
	private static final Map<String, List<Integer>> dataMap = new ConcurrentHashMap<>();

	public static void main(String[] args) {
//		String t1 = "083000";
//		String t2 = "083400";
//		System.out.println(isTimeDiffGreaterThanFiveMinutes(t1, t2));

		List<Float> numList = new ArrayList<>();
		numList.add(21152f);
		numList.add(17046f);
		numList.add(36652f); 

		float averageVolatility = calculateAverageVolatility(numList);
		System.out.println("平均波动率为: " + averageVolatility);
	}

}
